////	Trainer.h
#ifndef __DMC_TRAINER_H
#define __DMC_TRAINER_H

#include <Windows.h>
#include <tchar.h>
#include <MMSystem.h>
#include <map>
#include <ctime>
#include <process.h>
#include "ExcelFormat.h"
#pragma comment(lib,"winmm.lib")

#define  CreateThread(		\
	lpThreadAttributes,		\
	dwStackSize,			\
	lpStartAddress,			\
	lpParameter,			\
	dwCreationFlags,		\
	lpThreadId)				\
	(HANDLE)_beginthreadex((void*)lpThreadAttributes,	\
	(unsigned)(dwStackSize),							 \
	(unsigned (__stdcall *) (void *))(lpStartAddress),	  \
	(void*)(lpParameter),								   \
	(unsigned)(dwCreationFlags),							\
	(unsigned*)(lpThreadId) )


using namespace std;
using namespace ExcelFormat;

struct Camera
{	
	float m_Height;
	float m_Angle;
	float m_Distant;
	float m_SDistant;
	float m_JJ;
	float m_Speed;
	Camera(float height=170.f,float angle=0.2f,float distant=550.f,float sDistant=520.f,float jj=55.f,float speed=1.0f)
	{
		m_Height=height;
		m_Angle=angle;
		m_Distant=distant;
		m_SDistant=sDistant;
		m_JJ=jj;
		m_Speed=speed;
	}
	static int f;//static
	void SetRand()
	{
		f=-f;
		m_JJ-=f*20;
	}
};


class Trainer
{
	int MessageBox(LPCTSTR lpctstr)
	{
		return ::MessageBox(NULL,lpctstr,L"ERROR",MB_OK);
	}
public:
	DWORD p;
	HANDLE DMC;
	HANDLE ThreadCamera;
	HANDLE ThreadSpeed;
	bool bCameraActive;
	bool bSpeedActive;
	bool bColorActive;
	bool bSpeed;
	bool bCamera;
public:
	map<WORD,Camera> Nero;
	map<WORD,Camera> NeroBoss;
	map<WORD,Camera> Dante;
	map<WORD,Camera> DanteBoss;
	Trainer();
	~Trainer()
	{
		if(DMC)
		{
			CloseHandle(DMC);DMC=nullptr;
		}
		CloseHandle(ThreadCamera);
		CloseHandle(ThreadSpeed);
	}
	void	InitDefult();
	int		LoadorWrite(int bInitLoadWrite=1);
	int		Load(int);
	int		Write();
	int		OpenDMC();
	void	AllMision();
	void	AutoCharge();
	void	AutoSword();
	void	SetTurbo(BYTE);
	void	DirectAct();
	void	HideHP();
	void	KbWalk();
	void	LockDevil();
	void	LockHealth();
	void	MissionC();
	void	Pts();

	void	StopTime();
	void	SwordALL();
	void	SetHard(BYTE);
	void	SetBp(BYTE);
	void	SetBpRush(BYTE);
	void	SetMisson(BYTE);



	/************************************************************************/
	/*	Camera Control			*/
	/************************************************************************/
	
	void	SpeedSet(float Speed=1.0f);
	void	SpeedUp();
	void	SpeedDown();
	
	void CAngleDown()
	{	
		DWORD p1,p2,p3,p01,p02,p4,p5;
		float data;	
		ReadProcessMemory(DMC,(DWORD*)p,&p01,4,NULL);
		p01+=0xb0;
		ReadProcessMemory(DMC,(DWORD*)p01,&p02,4,NULL);
		if(p02==0)
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p1,4,NULL);
			p1=p1+0xd0;
			ReadProcessMemory(DMC,(DWORD*)p1,&p2,4,NULL);
			p2=p2+0x498;
			ReadProcessMemory(DMC,(DWORD*)p2,&p3,4,NULL);
			p3+=0xd4;
			ReadProcessMemory(DMC,(float*)p3,&data,4,NULL);	
			data=data-0.05f;
			WriteProcessMemory(DMC,(float*)p3,&data,4,NULL);
		}
		else
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p4,4,NULL);
			p4+=0xd4;
			ReadProcessMemory(DMC,(DWORD*)p4,&p5,4,NULL);
			p5+=0x480;
			ReadProcessMemory(DMC,(DWORD*)p5,&data,4,NULL);
			data=data-0.05f;
			WriteProcessMemory(DMC,(float*)p5,&data,4,NULL);
		}
	}
	void CAngleUp()
	{	
		DWORD p1,p2,p3,p01,p02,p4,p5;
		float data;	
		ReadProcessMemory(DMC,(DWORD*)p,&p01,4,NULL);
		p01+=0xb0;
		ReadProcessMemory(DMC,(DWORD*)p01,&p02,4,NULL);
		if(p02==0)
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p1,4,NULL);
			p1=p1+0xd0;
			ReadProcessMemory(DMC,(DWORD*)p1,&p2,4,NULL);
			p2=p2+0x498;
			ReadProcessMemory(DMC,(DWORD*)p2,&p3,4,NULL);
			p3+=0xd4;
			ReadProcessMemory(DMC,(float*)p3,&data,4,NULL);	
			data=data+0.05;
			WriteProcessMemory(DMC,(float*)p3,&data,4,NULL);
		}
		else
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p4,4,NULL);
			p4+=0xd4;
			ReadProcessMemory(DMC,(DWORD*)p4,&p5,4,NULL);
			p5+=0x480;
			ReadProcessMemory(DMC,(DWORD*)p5,&data,4,NULL);
			data=data+0.05;
			WriteProcessMemory(DMC,(float*)p5,&data,4,NULL);
		}
	}
	void CDistanceUp()
	{	
		DWORD p1,p2,p3,p01,p02,p4,p5;
		float data;	
		ReadProcessMemory(DMC,(DWORD*)p,&p01,4,NULL);
		p01+=0xb0;
		ReadProcessMemory(DMC,(DWORD*)p01,&p02,4,NULL);
		if(p02==0)
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p1,4,NULL);
			p1=p1+0xd0;
			ReadProcessMemory(DMC,(DWORD*)p1,&p2,4,NULL);
			p2=p2+0x498;
			ReadProcessMemory(DMC,(DWORD*)p2,&p3,4,NULL);
			p3+=0xd8;
			ReadProcessMemory(DMC,(float*)p3,&data,4,NULL);	
			data=data+30;
			WriteProcessMemory(DMC,(float*)p3,&data,4,NULL);
		}
		else
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p4,4,NULL);
			p4+=0xd4;
			ReadProcessMemory(DMC,(DWORD*)p4,&p5,4,NULL);
			p5+=0x3f4;
			ReadProcessMemory(DMC,(DWORD*)p5,&data,4,NULL);
			data=data+30.0;
			WriteProcessMemory(DMC,(float*)p5,&data,4,NULL);
		}

	}
	void CDistanceDown()
	{	
		DWORD p1,p2,p3,p01,p02,p4,p5;
		float data;	
		ReadProcessMemory(DMC,(DWORD*)p,&p01,4,NULL);
		p01+=0xb0;
		ReadProcessMemory(DMC,(DWORD*)p01,&p02,4,NULL);
		if(p02==0)
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p1,4,NULL);
			p1=p1+0xd0;
			ReadProcessMemory(DMC,(DWORD*)p1,&p2,4,NULL);
			p2=p2+0x498;
			ReadProcessMemory(DMC,(DWORD*)p2,&p3,4,NULL);
			p3+=0xd8;
			ReadProcessMemory(DMC,(float*)p3,&data,4,NULL);	
			data=data-30;
			WriteProcessMemory(DMC,(float*)p3,&data,4,NULL);
		}
		else
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p4,4,NULL);
			p4+=0xd4;
			ReadProcessMemory(DMC,(DWORD*)p4,&p5,4,NULL);
			p5+=0x3f4;
			ReadProcessMemory(DMC,(DWORD*)p5,&data,4,NULL);
			data=data-30.0;
			WriteProcessMemory(DMC,(float*)p5,&data,4,NULL);
		}
	}
	
	void CHightDown()
	{	
		DWORD p1,p2,p3,p01,p02,p4,p5;
		float data;	
		ReadProcessMemory(DMC,(DWORD*)p,&p01,4,NULL);
		p01+=0xb0;
		ReadProcessMemory(DMC,(DWORD*)p01,&p02,4,NULL);
		if(p02==0)
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p1,4,NULL);
			p1=p1+0xd0;
			ReadProcessMemory(DMC,(DWORD*)p1,&p2,4,NULL);
			p2=p2+0x498;
			ReadProcessMemory(DMC,(DWORD*)p2,&p3,4,NULL);
			p3+=0xd0;
			ReadProcessMemory(DMC,(float*)p3,&data,4,NULL);	
			data=data-30;
			WriteProcessMemory(DMC,(float*)p3,&data,4,NULL);
		}
		else
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p4,4,NULL);
			p4+=0xd4;
			ReadProcessMemory(DMC,(DWORD*)p4,&p5,4,NULL);
			p5+=0x3e0;
			ReadProcessMemory(DMC,(DWORD*)p5,&data,4,NULL);
			data=data-30.0;
			WriteProcessMemory(DMC,(float*)p5,&data,4,NULL);
		}	
	}
	void CHightUp()
	{	
		DWORD p1,p2,p3,p01,p02,p4,p5;
		float data;	
		ReadProcessMemory(DMC,(DWORD*)p,&p01,4,NULL);
		p01+=0xb0;
		ReadProcessMemory(DMC,(DWORD*)p01,&p02,4,NULL);
		if(p02==0)
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p1,4,NULL);
			p1=p1+0xd0;
			ReadProcessMemory(DMC,(DWORD*)p1,&p2,4,NULL);
			p2=p2+0x498;
			ReadProcessMemory(DMC,(DWORD*)p2,&p3,4,NULL);
			p3+=0xd0;
			ReadProcessMemory(DMC,(float*)p3,&data,4,NULL);	
			data=data+30;
			WriteProcessMemory(DMC,(float*)p3,&data,4,NULL);
		}
		else
		{
			ReadProcessMemory(DMC,(DWORD*)p,&p4,4,NULL);
			p4+=0xd4;
			ReadProcessMemory(DMC,(DWORD*)p4,&p5,4,NULL);
			p5+=0x3e0;
			ReadProcessMemory(DMC,(DWORD*)p5,&data,4,NULL);
			data=data+30.0;
			WriteProcessMemory(DMC,(float*)p5,&data,4,NULL);
		}	
	}
	
	void CDisLockDown()
	{	
		DWORD p1,p2,p3;
		ReadProcessMemory(DMC,(DWORD*)p,&p1,4,NULL);
		p1=p1+0xd0;
		ReadProcessMemory(DMC,(DWORD*)p1,&p2,4,NULL);
		p2=p2+0x498;
		ReadProcessMemory(DMC,(DWORD*)p2,&p3,4,NULL);
		p3+=0xdc;
		float data;
		ReadProcessMemory(DMC,(float*)p3,&data,4,NULL);	
		data=data-50;
		WriteProcessMemory(DMC,(float*)p3,&data,4,NULL);
	}
	void CDisLockUp()
	{	
		DWORD p1,p2,p3;
		ReadProcessMemory(DMC,(DWORD*)p,&p1,4,NULL);
		p1=p1+0xd0;
		ReadProcessMemory(DMC,(DWORD*)p1,&p2,4,NULL);
		p2=p2+0x498;
		ReadProcessMemory(DMC,(DWORD*)p2,&p3,4,NULL);
		p3+=0xdc;
		float data;
		ReadProcessMemory(DMC,(float*)p3,&data,4,NULL);	
		data=data+50;
		WriteProcessMemory(DMC,(float*)p3,&data,4,NULL);
	}


	//


	void	WriteSpeed(float v);
	void	TransSpeed(float v1,float v2,int t,int pt=40);
	void	ReadCamera(Camera *lp);
	void	WriteCamera(Camera *lp);
	void	WriteCamera(float Height,float Angle,float Distant,float SDistant,float jj);
	void	WriteCameraBoss(Camera *lp);
	void	WriteCameraBoss(float Height,float Angle,float Distant);
	WORD	ReadAction();
	WORD	ReadBOSSDanteAction();
	void	CreateCamera();
	static	DWORD WINAPI CameraProc(LPVOID lp);
	void	PauseCamera();

	void	CreateSpeed();
	static	DWORD WINAPI SpeedProc(LPVOID lp);

	void	CreateColor();
	static	DWORD WINAPI ColorProc(LPVOID lp);

	void StopThread()
	{
		bCameraActive=0;
		bSpeedActive=0;
		WaitForSingleObject(ThreadCamera,500);
		WaitForSingleObject(ThreadSpeed,500);
	}

	virtual int MyPlaySound()=0;


};


#endif//
